package userscript;
import java.util.ArrayList;

import com.badlogic.gdx.math.Vector2;

import Component.GameComponent;
import GameObj.GameObject;
import Component.PhysicComponent;
import Scene.SceneMgr;
public class bird 
{
	static Vector2 vPos = new Vector2(100,100); 
	static public boolean OnTouchDown(GameObject obj, int x, int y, int pointer, int button)
	{
		Vector2 vPos2 = new Vector2(x,y); 
		float dis = vPos.dst(vPos2);
		if (dis > 30)
		{
			Vector2 vPosRes = vPos2.sub(vPos);
			vPosRes.nor();
			vPosRes.mul(30);
			obj.SetPos(vPosRes.add(vPos));
			return true;
			
		}
		obj.SetPos((float)(x), (float)(y));
		return true;		
	}
	
	static public boolean OnTouchMove (GameObject obj, int x, int y, int pointer)
	{
		Vector2 vPos2 = new Vector2(x,y); 
		float dis = vPos.dst(vPos2);
		if (dis > 30)
		{

			Vector2 vPosRes = vPos2.sub(vPos);
			vPosRes.nor();
			vPosRes.mul(30);
			obj.SetPos(vPosRes.add(vPos));
			return true;
			
		}
		obj.SetPos((float)(x), (float)(y));
		return true;
	}
	
	
	static public boolean OnTouchUp (GameObject obj, int x, int y, int pointer, int btn)
	{
		Vector2 vPos2 = new Vector2(x,y); 
		float dis = vPos.dst(vPos2);
		Vector2 vPosRes = vPos.sub(vPos2);
		vPosRes = vPosRes.mul(0.4f);
		if (obj != null)
		{
			ArrayList<GameComponent> retval = new ArrayList<GameComponent>();
			obj.QueryComponentsByType(GameComponent.E_PHYSICOMPONENT, retval);
			if (retval.size() > 0)
			{
				PhysicComponent comp = (PhysicComponent)retval.get(0);
				if (comp != null)
				{
					comp.SetEnable(true);
					comp.body_.setLinearVelocity(vPosRes.x, vPosRes.y);
					
					
				}
				
			}
			
			SceneMgr.lvl.camera.FollowGameObj(obj);
		}
		return true;
	}
}
